package com.shujia.socket;


import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws Exception {
        //绑定端口
        ServerSocket serverSocket = new ServerSocket(8888);

        //等待客户端连接
        Socket accept = serverSocket.accept();
        System.out.println("连接成功");

        //坚守客户端数据
        InputStream inputStream = accept.getInputStream();

        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        char[] chars = new char[1024];
        //read  是读取到字符的数量
        //将读取到的字符存放到chars中
        int read = inputStreamReader.read(chars);

        String string = new String(chars, 0, read);
        System.out.println(string);

    }
}
